package cn.com.headfree.mouldshow.dao.impl;

import cn.com.headfree.entity.TPersonYearPoint;
import cn.com.headfree.mouldshow.dao.PersonYearPointDao;
import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("personYearPointDao")
public class PersonYearPointDaoImpl extends BaseDaoImpl<TPersonYearPoint> implements PersonYearPointDao {


    @Override
    public void saveInfo(TPersonYearPoint personYearPoint) {
        this.save(personYearPoint);
    }

    @Override
    public List<TPersonYearPoint> getLastYearPointByErpNo(String erpNo, Integer year) {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        String sql = "select t.* from t_person_year_point t where t.del_sign = 0 " ;
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" AND t.erp_no= ? ");
        arrayList.add(erpNo);
        sqlBuilder.append(" AND t.year= ? ");
        arrayList.add(year);
        sqlBuilder.append(" order by year desc, create_time desc ");
        return this.findAllBySQL(TPersonYearPoint.class, sqlBuilder.toString(),null,false,arrayList.toArray());
    }


    @Override
    public void updateTPersonYearPointByCondition(String erpNo, int year, Double remainPoint, String salaryGrade ){
        String sql = "update t_person_year_point t set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" t.remain_point = #{remain_point,jdbcType=DOUBLE}, ");
        sqlBuilder.append(" t.salary_grade = #{salary_grade,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.year=#{year,jdbcType=INTEGER} ");
        params.put("remain_point",remainPoint);
        params.put("salary_grade",salaryGrade);
        params.put("erp_no",erpNo);
        params.put("year",year);
        this.executeSql(sqlBuilder.toString(), params);
    }
}
